<?php

# PMB Online
# Aplikasi PMB Online untuk Pendaftaran Calon Mahasiswa di PT/PTS Indonesia
# 
# version 1.0
# class biaya
# file
# created Feb 6, 2013 4:50:03 PM
# 
# (c)2012, arif.laksito@gmail.com

if (!defined('BASEPATH'))
    exit('No direct script access allowed');

class Biaya extends SI_Model{
    
    var $data = array();

    public function __construct() {
        parent::__construct();
    }
    
    public function get(){
        $this->db->join('gelombang','gelombang.id_gel = biaya.id_gel');
        $this->db->join('jurusan','jurusan.id_jurusan = biaya.id_jurusan');
        $this->db->join('tha','tha.id_tha = gelombang.id_tha');
        $this->db->where('tha.status',1);
        $this->db->order_by('biaya.id_gel');        
        $que = $this->db->get('biaya');
        
        return $que->result_array();
    }
    
    public function get_by_id($id){
        $this->db->join('gelombang','gelombang.id_gel = biaya.id_gel');
        $this->db->join('jurusan','jurusan.id_jurusan = biaya.id_jurusan');        
        $this->db->where('id_biaya',$id);        
        $que = $this->db->get('biaya');
        
        return $que->row_array();
    }
    
    public function get_by_gel_jur($gel, $jenjang){
        $this->db->join('gelombang','gelombang.id_gel = biaya.id_gel');
        $this->db->join('jurusan','jurusan.id_jurusan = biaya.id_jurusan');    
        $this->db->join('tha_jur','jurusan.id_jurusan = tha_jur.id_jurusan');
        $this->db->join('tha','tha.id_tha = tha_jur.id_tha');
        $this->db->where('tha.status',1);
        $this->db->where('biaya.id_gel',$gel);        
        $this->db->where("biaya.id_jurusan = (select id_jurusan from jurusan where jenjang='$jenjang')");        
        $que = $this->db->get('biaya');
        
        return $que->row_array();
    }
    
    public function get_rincian($gel, $jur){
        $this->db->join('gelombang','gelombang.id_gel = biaya.id_gel');
        $this->db->join('jurusan','jurusan.id_jurusan = biaya.id_jurusan');    
        $this->db->join('tha_jur','jurusan.id_jurusan = tha_jur.id_jurusan');
        $this->db->join('tha','tha.id_tha = tha_jur.id_tha');
        $this->db->where('tha.status',1);
        $this->db->where('biaya.id_gel',$gel);        
        $this->db->where("biaya.id_jurusan", $jur);        
        $que = $this->db->get('biaya');
        
        return $que->row_array();
    }
    
    public function get_beasiswa($gel, $jur){
        $this->db->where('id_gel', $gel);
        $this->db->where('id_jurusan', $jur);        
        $que = $this->db->get('biaya');
        
        return $que->row_array();
    }
    
    public function add($data = array()){
        $rules = array(            
            array('field' => 'id_gel', 'label' => 'Gelombang', 'rules' => 'required|is_natural_no_zero|trim'),
            array('field' => 'id_jurusan', 'label' => 'Jurusan', 'rules' => 'required|is_natural_no_zero|trim'),  
            array('field' => 'spa', 'label' => 'Biaya SPA', 'rules' => 'required|numeric|trim'),  
            array('field' => 'oka', 'label' => 'Biaya OKA', 'rules' => 'required|numeric|trim')            
        );

        if (!$this->set_field($rules)) {
            $this->umsg = $this->msg;
            return false;
        }
        
        if ($this->db->insert('biaya', $data)) {
            $this->umsg = 'Data Biaya berhasil ditambahkan';
            return true;
        } else {
            $this->umsg = 'Data Biaya gagal ditambahkan';
            return false;
        }
    }
    
    public function edit($id, $data = array()){
        $rules = array(            
            array('field' => 'id_gel', 'label' => 'Gelombang', 'rules' => 'required|is_natural_no_zero|trim'),
            array('field' => 'id_jurusan', 'label' => 'Jurusan', 'rules' => 'required|is_natural_no_zero|trim'),  
            array('field' => 'spa', 'label' => 'Biaya SPA', 'rules' => 'required|numeric|trim'),  
            array('field' => 'oka', 'label' => 'Biaya OKA', 'rules' => 'required|numeric|trim')            
        );

        if (!$this->set_field($rules)) {
            $this->umsg = $this->msg;
            return false;
        }
        
        $this->db->where('id_biaya',$id);
        if ($this->db->update('biaya', $data)) {
            $this->umsg = 'Data Biaya berhasil diedit';
            return true;
        } else {
            $this->umsg = 'Data Biaya gagal diedit';
            return false;
        }
    }
    
    public function delete($id){
        $this->db->where('id_biaya',$id);
        if($this->db->delete('biaya')){            
            return true;
        }else{
            return false;
        }
    }
    
}